// basicnpc.txt
// A very simple, naive text. Creature attacks anything it hates nearby.
// Once it has won, it returns to its home.
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3 - Number of state when talked to. Plays default text if 0.

begincreaturescript;

variables;

short i,target;
short which_tag;
short following = 0;

body;

beginstate INIT_STATE;
	set_level(ME,26);
	change_max_health(ME,100);
	set_boss_level(ME,1);
	set_attack_bonus(ME,15);
	
	if (my_number() == 27) {
		set_name(ME,"Captain Hoyt");
		which_tag = 15;
		}
	if (my_number() == 28) {
		set_name(ME,"Brawne");
		which_tag = 16;
		}
	if (my_number() == 29) {
		set_name(ME,"Silenus");
		which_tag = 16;
		}
	
	if (gf(29,9) > 0)
		erase_char(ME);
	if (gf(29,which_tag) > 1)
		erase_char(ME);
		
	break;


beginstate DEAD_STATE;
	if (which_tag == 15)
		sf(29,17,0);
	
break;

beginstate START_STATE; 
	if ((gf(29,which_tag) == 2) && (gf(100,13) > 1)) {
		sf(29,which_tag,3);
		print_named_str(ME,"hears the horde of shredbugs, panics, and runs for the exit.");
		}
		
	if (gf(29,which_tag) == 2)
		following = 1;
		else following = 0;

	if ((following) && (which_tag == 15)) { // hoyt close?
		sf(29,17,0);
		if (get_nearest_party_char(8) >= 0)
			sf(29,17,1);
		}
 
	// if I have a target fo some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
		
	if (following) {
		if (dist_to_pc() > 12) {
			print_named_str(ME,"runs to catch up with you.");
			telep_char_to_char(ME,pc_num(),FALSE);
			}
			else maintain_dist_to_char(ME,pc_num(),2);
		}
	if (gf(29,which_tag) == 3) {
		approach_nav_point(ME,3,2);
		if (dist_to_nav_point(ME,3) <= 1) {
			print_named_str(ME,"manages to escape. Hopefully the soldier can");
			print_str_color("  find the way back to Haria-Kel from here.",2);
			if (which_tag == 15)
				sf(29,17,0);
				
			award_party_xp(100,20);
			erase_char(ME);
			end();
			}
		}
		
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);


	do_attack();
break;

beginstate TALKING_STATE;
	if (following) 
		begin_talk_mode(90);
		else if (gf(29,which_tag) == 3) {
			print_str("Talking: This soldier is mainly concentrating on trying");
			print_str("  to escape.");
			}
			else begin_talk_mode(get_memory_cell(3));
break;